using System.Collections.Generic;
using UnityEngine;

namespace UIFramework.Window
{
    /// <summary>
    /// 这是一个“辅助”层，以便显示优先级更高的窗口
    /// 默认情况下，包含任何标记为弹出窗口的窗口，它由WindowUILayer控制
    /// </summary>
    public class WindowParaLayer : MonoBehaviour
    {
        [SerializeField] 
        private GameObject darkenBgObject = null;
        
        private List<GameObject> containedScreens = new List<GameObject>();

        /// <summary>
        /// 注册弹窗到节点上
        /// </summary>
        /// <param name="screenRectTransform"></param>
        public void AddScreen(Transform screenRectTransform)
        {
            screenRectTransform.SetParent(transform, false);
            containedScreens.Add(screenRectTransform.gameObject);
        }

        public void RefreshDarken()
        {
            for (int i = 0; i < containedScreens.Count; i++)
            {
                if (containedScreens[i] != null)
                {
                    if (containedScreens[i].activeSelf)
                    {
                        darkenBgObject.SetActive(true);
                        return;
                    }
                }
            }
            
            darkenBgObject.SetActive(false);
        }


        public void DarkenBG()
        {
            darkenBgObject.SetActive(true);
            darkenBgObject.transform.SetAsLastSibling();
        }
        
        
    }
}